import Vue from "vue";
import Vuex from "vuex";
import { storage } from "@/plugins/storage";
import api from "../api";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    userInfo: {}
  },
  mutations: {
    setUserInfo(state, session) {
      storage.set(
        "userInfo",
        session
      )
      state.userInfo = session;
    },
    ["UidRemove"](state) {
      state.userInfo = {};
      storage.clear();
    }
  },
  actions: {
    setUserInfo({ commit }) {
      return new Promise((resolve, reject) => {
        api.obtainUid().then(uidRes => {
          console.log("first", uidRes)
          api.obtainUser({
              userId: "202020401781176467456"
          }).then(result => {
              commit("setUserInfo", result);
          })
        });
      });
    }
  },
  modules: {
  }
});
